package cn.bytecollege.user.filter;

import cn.bytecollege.common.constant.Resource;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(filterName = "ResourcesFilter",urlPatterns = "/user/static/*")
public class ResourcesFilter implements Filter {
    /**
     * 静态资源过滤器
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request1 =(HttpServletRequest) request;
        //获取请求资源的路径
        String uri = request1.getRequestURI();
        //将请求转发至对应的目录
        request.getRequestDispatcher(Resource.PAGE_LOCATION +uri).forward(request, response);
    }
}
